package com.platform.dao.mybatis;

import com.platform.dao.UserDao;
import com.platform.dao.mybatis.mapper.TbSysUserAuthorizationMapper;
import com.platform.dao.mybatis.mapper.TbSysUserMapper;
import com.platform.dao.mybatis.mapper.TbSysUserSecurityMapper;
import com.platform.domain.*;
import com.platform.domain.query.TbSysUserQuery;
import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: wangyanginfo
 * Date: 12-8-21
 * Time: 上午10:16
 * To change this template use File | Settings | File Templates.
 */
@Service("userDao")
public class UserDaoImpl extends SqlSessionDaoSupport implements UserDao {

    @Resource
    private TbSysUserMapper tbSysUserMapper;

    @Resource
    private TbSysUserSecurityMapper tbSysUserSecurityMapper;

    @Resource
    private TbSysUserAuthorizationMapper tbSysUserAuthorizationMapper;

    /**
     * 根据主键查询用户
     *
     * @param userId 用户ID
     * @return 用户对象
     * @throws Exception
     */
    @Override
    public TbSysUser queryUser(String userId) throws Exception {
        return tbSysUserMapper.selectByPrimaryKey(userId);
    }

    /**
     * 根据登录名查询用户
     *
     * @param loginId 登录ID
     * @return 用户对象
     * @throws Exception
     */
    @Override
    public TbSysUser queryUserByLoginId(String loginId) throws Exception {
        TbSysUserQuery user = new TbSysUserQuery();
        user.setLoginId(loginId);
        List<TbSysUser> list = tbSysUserMapper.selectUserInfos(user);
        return list != null && list.size() == 1 ? list.get(0) : null;
    }

    /**
     * 根据用户对象条件查询符合条件的用户对象集合
     *
     * @param user 用户对象
     * @return 用户对象集合
     * @throws Exception
     */
    @Override
    public List<TbSysUser> queryUserInfos(TbSysUserQuery user) throws Exception {
        return tbSysUserMapper.selectUserInfos(user);
    }

    /**
     * 根据用户对象条件查询符合条件的用户记录总条数
     *
     * @param user 用户对象
     * @return 记录总条数
     * @throws Exception
     */
    @Override
    public int queryUserInfosCount(TbSysUserQuery user) throws Exception {
        return tbSysUserMapper.selectUserInfosCount(user);
    }

    /**
     * 插入新的用户
     *
     * @param user 用户对象
     * @return 执行是否成功标识
     * @throws Exception
     */
    @Override
    public int insertUser(TbSysUser user) throws Exception {
        return tbSysUserMapper.insert(user);
    }

    /**
     * 更新用户分类
     *
     * @param user 用户对象
     * @return 执行是否成功标识
     * @throws Exception
     */
    @Override
    public int updateUser(TbSysUser user) throws Exception {
        return tbSysUserMapper.update(user);
    }

    /**
     * 根据主键删除用户
     *
     * @param userId 用户ID
     * @return 执行是否成功标识
     * @throws Exception
     */
    @Override
    public int deleteUser(String userId) throws Exception {
        return tbSysUserMapper.delete(userId);
    }

    /**
     * 根据主键查询用户安全问题
     *
     * @param key 用户安全问题KEY
     * @return 用户安全问题对象
     * @throws Exception
     */
    @Override
    public TbSysUserSecurity queryUserSecurity(TbSysUserSecurityKey key) throws Exception {
        return null;
    }

    /**
     * 根据主键查询用户安全问题
     *
     * @param userSecurity 用户安全问题
     * @return 用户安全问题对象集合
     * @throws Exception
     */
    @Override
    public List<TbSysUserSecurity> queryUserSecurity(TbSysUserSecurity userSecurity) throws Exception {
        return null;
    }

    /**
     * 插入用户安全问题
     *
     * @param userSecurity 用户安全问题
     * @return 执行是否成功标识
     * @throws Exception
     */
    @Override
    public int insertUserSecurity(TbSysUserSecurity userSecurity) throws Exception {
        return 0;
    }

    /**
     * 更新用户安全问题
     *
     * @param userSecurity 用户安全问题
     * @return 执行是否成功标识
     * @throws Exception
     */
    @Override
    public int updateUserSecurity(TbSysUserSecurity userSecurity) throws Exception {
        return 0;
    }

    /**
     * 根据主键删除用户安全问题
     *
     * @param key 用户安全问题KEY
     * @return 执行是否成功标识
     * @throws Exception
     */
    @Override
    public int deleteUserSecurity(TbSysUserSecurityKey key) throws Exception {
        return 0;
    }

    /**
     * 根据主键查询用户授权信息
     *
     * @param key 用户授权信息KEY
     * @return 用户授权信息对象
     * @throws Exception
     */
    @Override
    public TbSysUserAuthorization queryUserAuthorization(TbSysUserAuthorizationKey key) throws Exception {
        return tbSysUserAuthorizationMapper.selectByPrimaryKey(key);
    }

    /**
     * 根据用户授权查询用户授权信息
     *
     * @param userAuthorization 用户授权信息
     * @return 用户授权信息对象集合
     * @throws Exception
     */
    @Override
    public List<TbSysUserAuthorization> queryUserAuthorization(TbSysUserAuthorization userAuthorization) throws Exception {
        return tbSysUserAuthorizationMapper.select(userAuthorization);
    }

    /**
     * 插入用户授权信息
     *
     * @param userAuthorization 用户授权信息
     * @return 执行是否成功标识
     * @throws Exception
     */
    @Override
    public int insertUserAuthorization(TbSysUserAuthorization userAuthorization) throws Exception {
        return tbSysUserAuthorizationMapper.insert(userAuthorization);
    }

    /**
     * 更新用户授权信息
     *
     * @param userAuthorization 用户授权信息
     * @return 执行是否成功标识
     * @throws Exception
     */
    @Override
    public int updateUserAuthorization(TbSysUserAuthorization userAuthorization) throws Exception {
        return tbSysUserAuthorizationMapper.update(userAuthorization);
    }

    /**
     * 根据主键删除用户授权信息
     *
     * @param key 用户授权信息KEY
     * @return 执行是否成功标识
     * @throws Exception
     */
    @Override
    public int deleteUserAuthorization(TbSysUserAuthorizationKey key) throws Exception {
        return tbSysUserAuthorizationMapper.deleteByPrimaryKey(key);
    }

    /**
     * 根据用户ID删除用户授权信息
     *
     * @param userId 用户ID
     * @return 执行是否成功标识
     * @throws Exception
     */
    @Override
    public int deleteUserAuthorizationByUserId(String userId) throws Exception {
        return tbSysUserAuthorizationMapper.deleteByUserId(userId);
    }


}
